package cn.zyq.ykb.controller.tk;

import cn.zyq.ykb.beans.config.ConfigProp;
import cn.zyq.ykb.mapper.tk.TUserMapper;
import cn.zyq.ykb.service.config.ConfigPropService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import cn.zyq.ykb.system.ry.util.poi.ExcelUtil;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import cn.zyq.ykb.beans.tk.TUser;
import cn.zyq.ykb.service.tk.TUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.zyq.ykb.system.common.PageParam;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户Controller
 *
 * @author SystemAuth
 * @date 2023-07-03
 */

@RestController(value = "H5TUserController")
@RequestMapping("/api/tUser")
@Api(tags = "用户接口")
@Slf4j
public class TUserController extends BaseController {

    @Autowired
    private TUserService tuserService;
    @Autowired
    private ConfigPropService configPropService;
    @Autowired
    private TUserMapper tUserMapper;

    /**
     * 套壳注册
     */
    @ApiOperation(value = "套壳注册", response = TUser.class)
    @GetMapping("/register/{phone}/{smsCode}")
    public Object register(@PathVariable("phone") String phone, @PathVariable("smsCode") String smsCode) {
        return this.tuserService.register(phone,smsCode);
    }

    /**
     * 手机密码登录
     */
    @ApiOperation(value = "手机密码登录", response = TUser.class)
    @GetMapping("/login/{phone}/{smsCode}")
    public Object login(@PathVariable("phone") String phone, @PathVariable("smsCode") String smsCode) {
        return this.tuserService.login(phone,smsCode);
    }

    /**
     * 套壳注册
     */
    @ApiOperation(value = "手机密码短信验证码注册", response = TUser.class)
    @GetMapping("/loginByPassword/{phone}/{smsCode}/{password}")
    public Object loginByPassword(@PathVariable("phone") String phone,
                                  @PathVariable("smsCode") String smsCode,
                                  @PathVariable("password")String password) {
        return this.tuserService.loginByPassword(phone,smsCode,password);
    }

    /**
     * 刷新置顶下单购买
     */
    @ApiOperation(value = "刷新置顶下单购买", response = ConfigProp.class)
    @PostMapping("/propOrder")
    public Object propOrder(@RequestBody ConfigProp pageParam) {
        return this.configPropService.pay(pageParam,this.request);
    }
    /**
     * 查询用户信息
     */
    @ApiOperation(value = "查询用户信息", response = TUser.class)
    @GetMapping("/userInfo/{phone}")
    public Object userInfo(@PathVariable("phone") String phone) {
        TUser tUser = new TUser();
        tUser.setDeleted(0);
        tUser.setPhone(phone);
        return this.tUserMapper.selectOne(tUser);
    }

    /**
     * 修改用户信息
     */
    @ApiOperation(value = "修改用户信息", response = TUser.class)
    @PostMapping("/upt")
    public Object upt(@RequestBody TUser tUser) {
        log.info("入参 ---------------------------------{}",tUser.toString());
        return this.tUserMapper.updateByPrimaryKeySelective(tUser);
    }
}
